import { requestClient } from '#/api/request'

import { downloadFileFromBlobPart } from '@vben/utils'

/**
 * 获取货物采购进度SKU列表
 */
export async function getGoodsPurchaseTotalSkuList(params: any) {
  return requestClient.get('/admin/GoodsPurchaseTotalSku/index', params)
}

/**
 * 导出报表
 */
export async function exportData(params: any) {
  const res = await requestClient.post('/admin/GoodsPurchaseTotalSku/downPurchaseRecord', params)

  const blob = new Blob([res.data], {
    type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  })
  downloadFileFromBlobPart({
    source: blob,
    fileName: '采购进度报表.xlsx',
  })
}

/**
 * 直接导出报表
 */
export async function exportData2(params: any) {
  const res = await requestClient.get('/admin/GoodsPurchaseTotalSku/index', params, {
    responseType: 'blob',
    responseReturn: 'raw',
  })

  const blob = new Blob([res.data], {
    type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  })
  downloadFileFromBlobPart({
    source: blob,
    fileName: '采购进度.xlsx',
  })
}

/**
 * 登记交期
 */
export async function reportPurchaseDeadLine(params: any) {
  return requestClient.post('/admin/GoodsPurchaseTotalSku/reportPurchaseDeadLine', params)
}

/**
 * 导出补单数据
 */
export async function exportAddOrderData(params: any) {
  const res = await requestClient.get('/admin/GoodsPurchaseTotalSku/exportAddOrderData', params, {
    responseType: 'blob',
    responseReturn: 'raw',
  })

  const blob = new Blob([res.data], {
    type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  })
  downloadFileFromBlobPart({
    source: blob,
    fileName: '补单数据.xlsx',
  })
}

/**
 * 获取货品分类选项
 */
export async function getGoodsCategoryOptions(params: any) {
  return requestClient.get('/admin/goodsCategory/allIndex', params)
}

/**
 * 获取时间分类选项
 */
export async function getGoodsTimeCategoryOptions(params: any) {
  return requestClient.get('/admin/goodsTimeCategory/allIndex', params)
}

/**
 * 保存搜索条件
 */
export async function saveSearchTemplate(params: any) {
  return requestClient.post('/admin/SearchTemplate/search_template_add', params).then((res) => {
    return res
  })
}

/**
 * 获取搜索条件列表
 */
export async function getSearchTemplateList(params: any) {
  return requestClient.post('/admin/SearchTemplate/search_template_list', params)
}
